var vm_shenhelist_shenhe = new Vue({
    el : "#shenhelist_shenhe",
    data : {
        deptid : $("#deptid").val(),		// 单位ID
        userid : $("#userid").val(),
        username : $("#username").val(),

        shenhelist : [],//
        renwuid : '',//
        shenhe : {},//
        biandong : {},//变动表
        piliangshenhelist : [],
        shenhejilulist : [],

        //查询用字段
        shenhezhuangtai : '99',//0待审核 1通过 2未通过
        jigoumingcheng : '',
        zhuanjiaxingming : '',
        renwuxiafashijian1 : '',
        renwuxiafashijian2 : '',
        renwuwanchengshijian1 : '',
        renwuwanchengshijian2 : '',
        biandongleixing:'',

        shenheyijian : '',//审核意见

        pageindex : 1,		// 查询分页初始化页
        pagesize : 10,		// 查询分页初始化页面大小
        pageCount : 0,		// 总页数
        recordCount : 0,	// 总记录数
        targetpage : '', 	// 目标页
    },
    watch : {
        //监控分页情况，刷新列表
        pageindex : function(){
            this.bindShenheList();
        },

        pagesize : function(){
            //
            this.bindShenheList();
        },

        shenhezhuangtai : function(){
            this.bindShenheList();
        }
    },
    created : function(){
        var _this = this;

        _this.bindShenheList();

    },
    methods : {

        //
        bindShenheList : function(){
            var _this = this;

            var shenhe_layer = layer.open({type:3});
            $.post('/system/renwu/findshenhelist', {
                deptid : _this.deptid,
                shenhezhuangtai : _this.shenhezhuangtai,
                jigoumingcheng : _this.jigoumingcheng,
                zhuanjiaxingming : _this.zhuanjiaxingming,
                renwuxiafashijian1 : _this.renwuxiafashijian1,
                renwuxiafashijian2 : _this.renwuxiafashijian2,
                renwuwanchengshijian1 : _this.renwuwanchengshijian1,
                renwuwanchengshijian2 : _this.renwuwanchengshijian2,
                biandongleixing:_this.biandongleixing,
                pageindex : _this.pageindex,
                pagesize : _this.pagesize,
                rdm : Math.random()
            },function(ppData) {
                layer.close(shenhe_layer);

                if (ppData != null) {
                    var data = ppData.resultContent;
                    _this.shenhelist = data.shenhelist;

                    var pageInfo = data.PageInfo;
                    _this.pageindex = pageInfo.pageIndex;
                    _this.pageCount = pageInfo.pageCount;
                    _this.recordCount = pageInfo.recordCount;
                    _this.targetpage = '';
                }
            },"json");
        },

        ShowShenheModal:function(shenheitem){
            var _this = this;
            _this.shenhe = shenheitem;

            $("#myModalLabel").html("专家变动情况审核");
            $("#modal-dialog").attr("style","width:1200px;");
            $("#shenheModal").modal();
        },

        //未完成
        Shenhe:function(ppShenhejieguo){
            var _this = this;
            if (_this.checkInputData(ppShenhejieguo)) {
                var biandong_layer = layer.open({type: 3});
                $.post('/system/renwu/shenhe_biandong', {
                    id:_this.shenhe.id,
                    shiwuid: _this.shenhe.shiwuid,
                    renwuid: _this.shenhe.renwuid,
                    shenherenid:_this.userid,
                    shenheren:_this.username,
                    shifoutongguo:ppShenhejieguo,
                    shenheyijian:_this.shenheyijian,
                    deptid:_this.deptid,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.close(biandong_layer);
                    if (ppData != null) {

                        if (ppData.result == "1") {
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "审核成功!",
                            });

                            _this.refresh();
                            $("#shenheModal").modal('hide');

                        } else {
                            layer.alert(ppData.message);
                        }
                    }
                }, "json");
            }
        },

        //检查项目数据
        checkInputData : function(ppShenhejieguo) {
            if (ppShenhejieguo==2){

                if (!$.trim(this.shenheyijian)) {
                    layer.alert("请填写审核意见！");
                    return false;
                }
            }

            return true;
        },

        Export:function () {
            var _this = this
            location.href = "/export/biandongshenhe?deptid="+this.deptid
                +"&shenhezhuangtai="+_this.shenhezhuangtai
                +"&jigoumingcheng="+_this.jigoumingcheng
                +"&zhuanjiaxingming="+_this.zhuanjiaxingming
                +"&renwuxiafashijian1="+_this.renwuxiafashijian1
                +"&renwuxiafashijian2="+_this.renwuxiafashijian2
                +"&renwuwanchengshijian1="+_this.renwuwanchengshijian1
                +"&renwuwanchengshijian2="+_this.renwuwanchengshijian2
                +"&biandongleixing="+_this.biandongleixing

        },

        refresh:function(){
            var _this = this;

            _this.bindShenheList();
        },

        toDetail : function(ppBiandongitem){
            this.biandong =ppBiandongitem;
            $('[name="zhuanli"]').hide();
            $("#myModalLabel3").html("专家变动详情");
            $("#biandongdetailModal").modal();
        },

        showShenhejiluModel:function(ppShiwuId){
            var _this = this;

            $("#shenhejiluModalLabel").html("审核进度");
            $("#shenhejiluModal").modal();

            _this.bindShenhejilu(ppShiwuId);
        },

        bindShenhejilu:function(ppShiwuId){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/renwu/findshenhejilu', {
                shiwuid : ppShiwuId,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    var data = ppData;
                    _this.shenhejilulist = data.resultContent;
                }
            },"json");
        },

        toPiliangShenhe(){
            var _this = this;

            var chk_value =[];

            _this.piliangshenhelist = [];

            $('input[name="checkbox"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            if (chk_value.length==0){
                layer.alert('您还没有选择任何专家变动！');
            }else{
                for(var i=0;i<chk_value.length;i++){
                    for(var j=0;j<_this.shenhelist.length;j++){
                        if (chk_value[i]==_this.shenhelist[j].id){

                            _this.piliangshenhelist.push(_this.shenhelist[j]);

                        }
                    }
                }

                console.log(_this.piliangshenhelist);

                $("#piliangModalLabel").html("专家变动情况批量审核");
                $("#modal-dialog").attr("style","width:1200px;");
                $("#piliangshenheModal").modal();
            }
        },

        piliangShenhe:function(ppShenhejieguo){
            var _this = this;

            var renwuids = '';
            var shiwuids = '';
            var ids = '';

            var chk_value =[];
            $('input[name="checkbox"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            if (chk_value.length==0){
                layer.alert('您还没有选择任何专家变动！');
            }else{
                for(var i=0;i<_this.piliangshenhelist.length;i++){
                    renwuids = renwuids+_this.piliangshenhelist[i].renwuid+";";
                    shiwuids = shiwuids+_this.piliangshenhelist[i].shiwuid+";";
                    ids = ids+_this.piliangshenhelist[i].id+";";
                }
            }

            if (_this.checkInputData(ppShenhejieguo)) {
                var biandong_layer = layer.open({type: 3});
                $.post('/system/renwu/piliangshenhe_biandong', {
                    //shenhelist : _this.piliangshenhelist,
                    renwuids:renwuids,
                    shiwuids:shiwuids,
                    ids:ids,
                    shenherenid:_this.userid,
                    shenheren:_this.username,
                    shifoutongguo:ppShenhejieguo,
                    shenheyijian:_this.shenheyijian,
                    deptid:_this.deptid,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.close(biandong_layer);
                    if (ppData != null) {

                        if (ppData.result == "1") {
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: ppData.resultContent,
                            });

                            _this.refresh();
                            $("#piliangshenheModal").modal('hide');

                        } else {
                            layer.alert(ppData.message);
                        }
                    }
                }, "json");
            }
        },

        getDate_chaxun:function(){
            var _this = this;
            _this.renwuxiafashijian1=$("#renwuxiafashijian1_chaxun").val();
            _this.renwuxiafashijian2=$("#renwuxiafashijian2_chaxun").val();
            _this.renwuwanchengshijian1=$("#renwuwanchengshijian1_chaxun").val();
            _this.renwuwanchengshijian2=$("#renwuwanchengshijian2_chaxun").val();
        },

        reset:function(){
            var _this = this;
            _this.shenhezhuangtai = '99';
            _this.jigoumingcheng = "";
            _this.zhuanjiaxingming = "";
            _this.renwuxiafashijian1 = "";
            _this.renwuxiafashijian2 = "";
            _this.renwuwanchengshijian1 = "";
            _this.renwuwanchengshijian2 = "";
            _this.biandongleixing=""
            _this.bindShenheList()
        },

        //全选按钮的点击事件
        checkAll(){
            //获取id的dom元素
            let Id = document.getElementById('allAndNotAll');
            //获取类名为chBox的dom元素
            let chBox = document.getElementsByName('checkbox');
            let len = chBox.length;
            //输出观察

            for(let i=0;i<len;i++){
                //当全选按钮为true时，全部按钮都为true，否则相反
                if(Id.checked){
                    chBox[i].checked=true;
                }
                else {
                    chBox[i].checked=false;
                }
            }
        },
        //单个按钮的点击事件
        checkOne(){
            let count=0;
            let chBox = document.getElementsByName('checkbox');
            let len = chBox.length;
            for(let i=0;i<len;i++){
                //记录单选按钮为true的数量
                if(chBox[i].checked){
                    count++;
                }
            }
            //当单选按钮都为true时，全选按钮也为true，否则为false
            if(count==len){
                document.getElementById('allAndNotAll').checked = true;
            }else {
                document.getElementById('allAndNotAll').checked = false;
            }
        },


        //首页
        firstPage : function(){
            this.pageindex = 1;
        },
        //尾页
        lastPage : function(){
            this.pageindex = this.pageCount;
        },
        //上一页
        prePage : function(){
            var prePage = ((this.pageindex -1) <= 0) ? 1 : (this.pageindex -1);
            this.pageindex = prePage;
        },
        //下一页
        nextPage : function(){
            var nextPage = ((this.pageindex +1) >= this.pageCount) ? this.pageCount : (this.pageindex +1);
            this.pageindex = nextPage;
        },
        //跳到目标页
        targetPage : function() {
            if( this.targetpage != '' && this.targetpage <= this.pageCount && this.targetpage > 0){
                this.pageindex = this.targetpage;
                this.targetpage = '';
            }
        },
    },
});